<template>
 <div >
<div class="title"> 登录</div>
  <van-form @submit="onSubmit">
        
  <van-field
    v-model="username"
    name="企业账号"
    label="企业账号"
    placeholder="企业账号"
    :rules="[{ required: true, message: '请填写企业账号' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">
      登录
    </van-button>
  </div>
 
</van-form>
   </div>
</template>
<script>
import { setToken} from '@/utils/auth'
export default {
    data(){
        return{
      username: '',
      password: '',
        }
    },
    methods:{
        onSubmit() {
          const parm = {
            "supplierAccount":this.username,
            "supplierPassword":this.password
          }
          this.$api.login(parm).then(res => {
            if(res.code===0){
              this.$toast(res.msg)
              setToken(res.token)
              this.$router.replace('/home')
            } else {
               this.$toast(res.msg)
            }
       
          }).catch(error => {
             this.$toast(error)
          })
           
        }
    }
}
</script>